package com.xzq.erp.controller;


import com.xzq.erp.aspect.ApiOperationLog;
import com.xzq.erp.domain.dto.PageDTO;
import com.xzq.erp.domain.dto.ProductStockDTO;
import com.xzq.erp.domain.dto.WarehouseStockRecordDTO;
import com.xzq.erp.domain.query.ProductStockPageQuery;
import com.xzq.erp.domain.vo.ProductStockListVO;
import com.xzq.erp.domain.vo.ProductStockVO;
import com.xzq.erp.service.IProductStockService;
import com.xzq.erp.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品库存表 前端控制器
 * </p>
 *
 * @author xzq
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/product/stock")
@RequiredArgsConstructor
@Tag(name = "商品库存接口")
public class ProductStockController {

    private final IProductStockService productStockService;

    @GetMapping("/{id}")
    @Operation(summary = "商品库存详情")
    @ApiOperationLog(description = "商品库存详情")
    public Response<List<ProductStockVO>> getProductStock(@PathVariable Long id) {
        return Response.success(productStockService.getProductStock(id));
    }

    @GetMapping("/list")
    @Operation(summary = "商品采购信息分页查询")
    @ApiOperationLog(description = "商品采购信息分页查询")
    public Response<PageDTO<ProductStockListVO>> getProductStockList(@ParameterObject @Validated  ProductStockPageQuery query) {
        return Response.success(productStockService.getProductStockList(query));
    }

    @PutMapping("/record")
    @Operation(summary = "商品采购状态修改")
    @ApiOperationLog(description = "商品采购状态修改")
    public Response<Void> updateProductRecord(@RequestBody @Validated WarehouseStockRecordDTO warehouseStockRecordDTO) {
        productStockService.updateProductRecord(warehouseStockRecordDTO);
        return Response.success();
    }

    @PostMapping("/purchase")
    @Operation(summary = "商品采购信息添加")
    @ApiOperationLog(description = "商品采购信息添加")
    public Response<Void> addProductStock(@RequestBody @Validated ProductStockDTO productStockDTO) {
        productStockService.addProductStock(productStockDTO);
        return Response.success();
    }

    @PutMapping("/purchase")
    @Operation(summary = "商品采购信息修改")
    @ApiOperationLog(description = "商品采购信息修改")
    public Response<Void> updateProductStock(@RequestBody @Validated ProductStockDTO productStockDTO) {
        productStockService.updateProductStock(productStockDTO);
        return Response.success();
    }
}
